function generateMfuncNum_file(nameSteadyStateFile,allModelParams,y,x,xp,yp,strucOfArrays,positionFile,nameOfFunction)
% This function generates an M function which computes the f-function at the steady state
% The results are saved in the file nameOfFunction, for instance 
% nameOfFunction = 'numF.m';

% We start deleting the old version of the file - if it exists
saveFile = [positionFile,'\',nameOfFunction];
if exist(saveFile,'file') > 0
    delete(saveFile)
end

text = ['function [auxOut,f,errorMes] = ',nameOfFunction(1:end-2),'(params)'];
dlmwrite(saveFile,text,'-append','delimiter','');
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '% Computing the steady ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = nameSteadyStateFile;
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'params = auxOut.params;';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'xss = auxOut.xssTrans;';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'yss = auxOut.yssTrans;';
dlmwrite(saveFile,text,'-append','delimiter','');
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '%Unfold params';
dlmwrite(saveFile,text,'-append','delimiter','');
for i=1:length(allModelParams)
    text = [allModelParams{i}, '= params.',allModelParams{i},';'];
    dlmwrite(saveFile,text,'-append','delimiter','');
end 
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '% Current values in the model;';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '% x;';
dlmwrite(saveFile,text,'-append','delimiter','');
for i=1:length(x)
     text = [char(x(i)),' = xss(', num2str(i),');'];
     dlmwrite(saveFile,text,'-append','delimiter','');
end
text = '% xp;';
dlmwrite(saveFile,text,'-append','delimiter','');
for i=1:length(x)
     text = [char(x(i)),'p',' = xss(', num2str(i),');'];
     dlmwrite(saveFile,text,'-append','delimiter','');
end
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '% y';
dlmwrite(saveFile,text,'-append','delimiter','');
for i=1:length(y)
     text = [char(y(i)),' = yss(', num2str(i),');';];
     dlmwrite(saveFile,text,'-append','delimiter','');
end
text = '% yp;';
dlmwrite(saveFile,text,'-append','delimiter','');
for i=1:length(y)
     text = [char(y(i)),'p',' = yss(', num2str(i),');',];
     dlmwrite(saveFile,text,'-append','delimiter','');
end
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '%% Setting the dimension of f matrices ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'f  = zeros(length(xss)+length(yss),1);';
dlmwrite(saveFile,text,'-append','delimiter','');
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '%% f Function evaluation';
dlmwrite(saveFile,text,'-append','delimiter','');
DispSymMatrixMatlab_file(strucOfArrays.('f'),'f',saveFile);
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'end';
dlmwrite(saveFile,text,'-append','delimiter','');
end





